﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Helpers.Language;

namespace Helpers
{
    public static class ErrorHandling
    {
        public static void ShowError(string error)
        {
            WriteToLog(error);
            MessageBox.Show(error, LangRes.Get("ErrorOccured"), MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        public static void WriteToLog(string error)
        {
            using (var w = File.AppendText("log.txt"))
            {
                Log(error, w);
                w.Close();
            }
        }
        private static void Log(string logMessage, TextWriter w)
        {
            w.WriteLine("{0} {1} : {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), logMessage);
            w.Flush();
        }
    }
}
